using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace FluidDemo.Model
{
    public static class SpringResolver
    {
        public static void Solve(Particle p, ParticleRelation rel)
        {
            Particle p2 = rel.Particle;
            Vector2 x1 = p.Position;
            Vector2 x2 = p2.Position;
            Vector2 delta = x2 - x1;
            float deltalength = delta.Length();
            float diff = (deltalength - rel.Length) / (deltalength * (p.OneOverMass + p2.OneOverMass));
            if (float.IsInfinity(diff)) return;
            x1 += delta * p.OneOverMass * diff;
            x2 -= delta * p2.OneOverMass * diff;
            p.Position = x1;
            p2.Position = x2;
        }
    }
}
